package com.hserver.docker.utils;

import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.core.DefaultDockerClientConfig;
import com.github.dockerjava.core.DockerClientConfig;
import com.github.dockerjava.core.DockerClientImpl;
import com.github.dockerjava.core.exec.RemoveSwarmNodeCmdExec;
import com.github.dockerjava.jaxrs.JerseyDockerHttpClient;
import com.hserver.docker.config.ConstConfig;

/**
 * @author hxm
 */
public class DockerUtil {

    /**
     * 获取docker连接，没有持久使用
     *
     * @return
     */
    public static DockerClient getDocker(String name) {
        DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder()
                .withDockerHost(name)
                .build();
        JerseyDockerHttpClient httpClient = new JerseyDockerHttpClient.Builder().dockerHost(config.getDockerHost()).build();
        return DockerClientImpl.getInstance(config, httpClient);
    }

    /**
     * 默认
     *
     * @return
     */
    public static DockerClient getDocker() {
        return getDocker(ConstConfig.DOCKER_URL);

    }

}
